/*
 * @lc app=leetcode.cn id=20 lang=javascript
 *
 * [20] 有效的括号
 */

// @lc code=start
/**
 * @param {string} s
 * @return {boolean}
 */
var isValid = function (s) {
  const hash = {
    '}': '{',
    ']': '[',
    ')': '(',
  }
  let stack = []
  for (let k of s) {
    if (hash[k]) {
      if (stack.length === 0 || stack[stack.length - 1] !== hash[k]) {
        return false
      }
      stack.pop()
    } else {
      stack.push(k)
    }
  }
  if (stack.length === 0) {
    return true
  } else {
    return false
  }
}
// @lc code=end
